package com.ruoyi.system.mapper;

import java.util.List;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.system.domain.ByCouponUser;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;

import java.math.BigDecimal;


/**
 * 会员优惠券Mapper接口
 *
 * @author ruoyi
 * @date 2024-03-20
 */
public interface ByCouponUserMapper
{

    /**
     * 查询会员优惠券
     *
     * @param id 会员优惠券主键
     * @return 会员优惠券
     */
    public ByCouponUser selectByCouponUserById(Long id);

    /**
     * 查询会员优惠券列表
     *
     * @param byCouponUser 会员优惠券
     * @return 会员优惠券集合
     */
    public List<ByCouponUser> selectByCouponUserList(ByCouponUser byCouponUser);

    /**
     * 新增会员优惠券
     *
     * @param byCouponUser 会员优惠券
     * @return 结果
     */
    public int insertByCouponUser(ByCouponUser byCouponUser);

    /**
     * 修改会员优惠券
     *
     * @param byCouponUser 会员优惠券
     * @return 结果
     */
    public int updateByCouponUser(ByCouponUser byCouponUser);

    /**
     * 删除会员优惠券
     *
     * @param id 会员优惠券主键
     * @return 结果
     */
    public int deleteByCouponUserById(Long id);

    /**
     * 批量删除会员优惠券
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteByCouponUserByIds(Long[] ids);

    @Select("select * from by_coupon_user where userid = #{userid} and status = '0' order by price asc")
    List<JSONObject> getYhq(@Param("userid") String userid);

    @Select("select a.* from by_coupon_user a ,by_order b where a.userid = b.wx_id  and  b.wx_id = #{wxid}  and a.price < b.allprice and a.status = '0' ORDER BY a.price DESC")
    List<JSONObject> Zfyhq(@Param("wxid")String wxid);

    @Select("select price from by_coupon_user where id = #{yhqId} and status = '0'")
    BigDecimal getYhqById(@Param("yhqId") String yhqId);

    @Update("update by_coupon_user set flag = '1' where id = #{yhqId}")
    void updateStatus(@Param("yhqId") String yhqId);

    @Update("update by_coupon_user set flag = '0' where id = #{yhqId}")
    int updateYhqStatus(@Param("yhqId")String yhqId);

    @Update("update by_coupon_user set status = '1' where id = #{yhqId}")
    void applyById(@Param("yhqId")String yhqId);

    @Update("update by_coupon_user set status = '1' where userid = #{userid} and flag = '1'")
    void applyByUserId(@Param("userid") String userid);
}
